<template>
  <div class="home">
    <div class="head">
      <p @click="state.router.go('-1')">
        <van-icon name="arrow-left" />
      </p>
      <p>新房</p>
      <p></p>
    </div>

    <div class="nav">
      <p>北京</p>
      <p>
        <van-search v-model="state.values" placeholder="请输入搜索关键词" />
      </p>
      <p>地图找房</p>
    </div>

    <div class="select">
      <li class="boxli">
        <van-dropdown-menu>
          <van-dropdown-item title="区域" ref="item1">
            <li class="quyu1">
              <van-picker
                show-toolbar
                title
                :columns="state.price"
                toolbar-position="bottom"
                @confirm="onConfirm1"
                @cancel="onCancel1"
              />
            </li>
          </van-dropdown-item>
        </van-dropdown-menu>
      </li>
      <li class="boxli">
        <van-dropdown-menu>
          <van-dropdown-item title="租金" ref="item2">
            <li class="quyu1">
              <van-picker
                show-toolbar
                title
                :columns="state.price"
                toolbar-position="bottom"
                @confirm="onConfirm2"
                @cancel="onCancel2"
              />
            </li>
          </van-dropdown-item>
        </van-dropdown-menu>
      </li>
      <li class="boxli">
        <van-dropdown-menu>
          <van-dropdown-item title="户型" ref="item3">
            <li class="quyu1">
              <van-picker
                show-toolbar
                title
                :columns="state.typehome"
                toolbar-position="bottom"
                @confirm="onConfirm3"
                @cancel="onCancel3"
              />
            </li>
          </van-dropdown-item>
        </van-dropdown-menu>
      </li>
      <li class="boxli">
        <van-dropdown-menu>
          <van-dropdown-item title="朝向" ref="item4">
            <li class="quyu1">
              <van-picker
                show-toolbar
                title
                :columns="state.fx"
                toolbar-position="bottom"
                @confirm="onConfirm4"
                @cancel="onCancel4"
              />
            </li>
          </van-dropdown-item>
        </van-dropdown-menu>
      </li>
    </div>

    <div class="body">
      <dl v-for="(item,index) in list" :key="index">
        <dt>
          <img :src="item.img" alt />
        </dt>
        <dd>
          <li>
            <h4>{{item.title}}</h4>
          </li>
          <p>{{item.hometype}}</p>
          <p>
            <span>
              <h4 class="price">{{item.sumprice}}</h4>万
            </span>&nbsp;&nbsp;
            <span>{{item.price}}/m²</span>
          </p>
          <p>{{item.hometype}}</p>
        </dd>
      </dl>
    </div>
  </div>
</template>

<script>
import { defineComponent, reactive, ref, onMounted } from "vue";
import { useRouter } from "vue-router";
import api from "../utility/request";
import { Search } from "vant";
import { Picker } from "vant";
import { Toast } from "vant";
import { DropdownMenu, DropdownItem } from "vant";

export default defineComponent({
  components: {},

  data() {
    return {
      list: [],
      city: "",
      typehome:""
    };
  },

  setup(props, context) {
    const state = reactive({
      router: useRouter(),
      list: [],
      values: "",
      price: ["不限", "10w", "20w", "30w", "40w", "50w"],
      typehome: ["不限", "一室", "二室", "三室"],
      fx: ["不限", "东", "南", "西", "北"]
    });
    return {
      state
    };
  },

  created() {
    this.getList()
  },

  methods: {
    getList() {
      api
        .get("/getnewhome",{
          params:{
            keyword:toString(this.typehome)
          }
        })
        .then(res => {
          console.log(res.data.data);
          this.list = res.data.data;
        });
    },

    onConfirm1(value, index) {
      Toast(`当前值：${value}, 当前索引：${index}`);
      this.city = value;
      console.log(this.city);
      this.getList()
      this.$refs.item1.toggle();
    },
    onCancel1() {
      Toast("取消");
      this.$refs.item1.toggle();
    },


    //第二下拉
    onConfirm3(value, index) {
      Toast(`当前值：${value}, 当前索引：${index}`);
      this.typehome = value;
      console.log(this.typehome);
      this.getList()
      this.$refs.item3.toggle();
    },
    onCancel3() {
      Toast("取消");
      this.$refs.item3.toggle();
    }
  }
});
</script>

<style lang="scss" scoped>
.home {
  width: 100%;
  height: 100%;
}
.head {
  height: 8%;
  background: #1887f6;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.nav {
  height: 8%;
  display: flex;
  justify-content: space-around;
  align-items: center;
}

.select {
  width: 100%;
  height: 8%;
  background: #fff;
  display: flex;
  justify-content: space-between;
  .boxli {
    width: 25%;
  }
}

.body {
  dl {
    display: flex;
    margin-top: 10px;
  }
  img {
    width: 100px;
    height: 100px;
  }
  .price {
    display: inline-block;
    color: orange;
  }
}
</style>
